var EP=require('eventproxy');
var mock=require('./mock.js');

var ep=new EP();
ep.on('error',(err)=>{
    console.error(err);
});
ep.on('check',(sync)=>{
    sync&&mock.read(0,(err,read)=>{
        console.log('read:',err,read);
        if(err)return ep.emit('error',err);
        ep.emit('render',read);
    });
});

ep.on('render',(data)=>{
    data&&console.log('render:',data);
});

//将同步方法移到最后，保证先监听，后触发
mock.sync(0,(err,sync)=>{
    if(err)return em.emit('error',err);
    console.log('sync:',sync);
    ep.emit('check',sync);
});

